<?php
include __SB__.'Log.php';

function getConfig($e){
	$_config = unserialize(CONFIG);
	return $_config[$e];
}	

function S($param){
	return Service($param);
}

function D($param){
	return Model($param);
}

//直接操作数据库
function M($param){
	return \think\Db::name($param);
}

function Service($param){
		$Service = explode("/", $param);
		$_module = $Service[0];
		unset($Service[0]);
		$_class =  rtrim( $_module . "\\" . implode("\\", $Service) , "\\") . "Service";
		if(!class_exists($_class)){
			$data = array(
						"status"=>"404",
						"data"=>"Service:{$param}不存在"
					);
			exit(json_encode($data));
		}
		return new $_class();
}

function Model($param){
		$Model = explode("/", $param);
		$_module = $Model[0];
		unset($Model[0]);
		$_class =  rtrim( $_module . "\\" . implode("\\", $Model) , "\\") . "Model";
		if(!class_exists($_class)){
			$data = array(
						"status"=>"404",
						"data"=>"Model:{$param}不存在"
					);
			exit(json_encode($data));
		}
		return new $_class();
}

function successPage($e="运行成功",$ef="",$type="success"){
	$errtype = $type;
	$errstr = $e;
	$errfile = $ef;
	include __WEB_SYSTEM__ . "/success.php";
}

function errorPage($e="程序停止运行",$ef="",$type="halt"){
	$errtype = $type;
	$errstr = $e;
	$errfile = $ef;
	include __WEB_SYSTEM__ . "/error.php";
}